<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>清除浮动</title>
    <style>
      * {
        margin: 0;
        padding: 0;
      }

      div {
        border: 2px solid #f00;
        margin-bottom: 50px;
      }

      .clearfix::after {
        content: "";
        clear: both;
        display: block;
      }

      p {
        width: 100px;
        height: 100px;
        background-color: #ff0;
        margin-right: 10px;
        float: left;
        border: 1px solid #00f;
      }
    </style>
  </head>
  <body>
    <h1>清除浮动</h1>

    <div class="clearfix">
      <p>1</p>
      <p>2</p>
    </div>

    <div class="clearfix">
      <p>3</p>
      <p>4</p>
    </div>
  </body>
</html>
